package cn.com.idmy.mq.coder;

import com.alibaba.fastjson2.JSON;
import jakarta.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class FastjsonMqMsgEncoder implements MqMsgEncoder {
    @Override
    @Nullable
    public byte[] encode(Object body) {
        if (body == null) {
            log.warn("message body is empty.");
            return null;
        } else {
            return JSON.toJSONBytes(body);
        }
    }

    @Override
    @Nullable
    public String encodeString(Object body) {
        if (body == null) {
            log.warn("message body is empty.");
            return null;
        } else {
            return JSON.toJSONString(body);
        }
    }
}
